/*
 * @Description:
 * @Date: 2022-11-07 12:00:27
 * @LastEditors: czp
 * @LastEditTime: 2023-04-21 16:54:44
 */
import { useBaseStore } from "@/store/base";
import { Progress } from "@/utils/element/prompt";
import { Router, createRouter, createWebHashHistory } from "vue-router";

import { routes } from "./routes";

const router: Router = createRouter({
	history: createWebHashHistory(),
	routes: routes,
	strict: false,
	scrollBehavior: () => ({ left: 0, top: 0 })
});

/**
 * @description: 全局前置守卫
 * @param {*} to 即将要进入的目标
 * @param {*} from 当前导航正要离开的路由
 * @param {*} next
 * @return {*}
 * @Date: 2022-09-02 16:50:18
 */
router.beforeEach(async (to, from, next) => {
	Progress.start();
	const { setActivePath } = useBaseStore();
	setActivePath(to.path);
	next();
});

/**
 * @description: 全局后置钩子  它们对于分析、更改页面标题、声明页面等辅助功能以及许多其他事情都很有用。
 * @param {*} to
 * @param {*} from
 * @param {*} failure
 * @return {*}
 * @Date: 2022-09-02 16:58:01
 */
router.afterEach(() => {
	Progress.done();
});

export default router;
